<?php 

    $productRepository = new ProductRepository();
    $productName = "";
    $productName_Get = "-Any-";
    $categoryID ="-Any-";
    $colors = "-Any-";
    $arrColor = array();
    $arrCategoryID = array();
    if(isset($_GET['category_IDs']))
    {
        if($_GET['category_IDs'] != "-Any-")
        {
            $categoryID = $_GET['category_IDs'];
            $arrCategoryID = explode('|', $_GET['category_IDs']);
        }
    }
    if(isset($_GET['colors']))
    {
        if($_GET['colors'] != "-Any-")
        {
            $colors = $_GET['colors'];
            $arrColor = explode('|', $_GET['colors']);
        }
    }			
	if(isset($_GET['productName']))
	{
        if($_GET['productName'] != "-Any-")
        {
            $productName = $_GET['productName'];
        }
    }
    $curPage = 1;
    if(isset($_GET['page']))
    {
        if(is_numeric($_GET['page']))
            $curPage = $_GET['page'];
    }
    $totalItems = 0;
    $results = $productRepository->SearchProductPager($curPage, 9, $arrCategoryID, $arrColor, $productName, $totalItems);
    $generateLink = GenerateLink($totalItems, 5, 9, $curPage);
    
?>

<div id="right">
	<div class="box_content_t"></div>
	<div class="box_content_m">
		<!-- DEFINE YOUR CONTENT HERE -->
        <table border="0" width="100%" cellspacing="0" cellpadding="0"  class="cont_heading_table">
			<tr>
				<td><img src="../content/images/cont_heading_tl.gif" border="0" alt="" width="10" height="10" /></td>
				<td width="100%" class="cont_heading_t"><img src="../content/images/spacer.gif" border="0" alt="" width="1" height="1" /></td>
				<td><img src="../content/images/cont_heading_tr.gif" border="0" alt="" width="10" height="10" /></td>
			</tr>

			<tr>
				<td class="cont_heading_l"><img src="../content/images/spacer.gif" border="0" alt="" width="1" height="1" /></td>
				<td class="cont_heading_td">Kết quả tìm kiếm</td>
				<td class="cont_heading_r"><img src="../content/images/spacer.gif" border="0" alt="" width="1" height="1" /></td>
			</tr>
			<tr>
				<td><img src="../content/images/cont_heading_bl.gif" border="0" alt="" width="10" height="10" /></td>
				<td class="cont_heading_b"><img src="../content/images/spacer.gif" border="0" alt="" width="1" height="1" /></td>
				<td><img src="../content/images/cont_heading_br.gif" border="0" alt="" width="10" height="10" /></td>
			</tr>
		</table>
        <div class="productContent">
    		<div class="loading"></div>
            <div class="pagination pagination-left">
                <div class="results">
                    <span>
                        Kết quả từ <?php echo (($curPage - 1)*9 + (count($results) > 0 ? 1 : 0));?> - <?php echo (($curPage - 1)*9 + count($results));?> của <?php echo $totalItems ?>
                    </span>
                </div>
                <ul class="pager"><?php echo $generateLink ?></ul>
            </div>
            <div class="clearall"></div>
    		<table id="tblProducts" cellpadding="0" cellspacing="0">
                    <?php
                        $count = 0;
                        while($count < count($results))
                        { ?>
                <tr class="productsRow">        
                        <?php
                            for($i = $count; $i < count($results); $i++)
                            {?>
                    <td class="productCell">
    					<div><a class="link1" href="#"><?php echo $results[$i]->Name_s; ?></a></div>
    					<div class="clearall" style="margin-top:10px;"></div>
    					<div style="width:207px; text-align:center; border:1px solid #ebeaea; padding:5px 0 5px 0;">	
                        <?php
                            $arr = explode('|', $results[$i]->ImageSrc_s);                                            
                        ?>			
    						<a href="#"><img class="product1" alt="" src="../content/images/Products/<?php echo $results[$i]->Code_s;?>/<?php echo $arr[0];?>" /></a>
    					</div>
    					<div class="clearall" style="margin-top:10px;"></div>
    					<div style="float:left; width:167px; padding:0 20px 0 20px;">
    						<table cellpadding="0" cellspacing="0" border="0" class="cont_body_table_2" style="float:left; width:97px;">
    							<tr>
    								<td><img src="../content/images/cont_body_corn_tl_2.gif" border="0" alt="" width="10" height="10" /></td>
    								<td width="100%" class="cont_body_tall_t_2"><img src="../../Content/images/spacer.gif" border="0" alt="" width="1" height="1" /></td>
    								<td><img src="../content/images/cont_body_corn_tr_2.gif" border="0" alt="" width="10" height="10" /></td>
    							</tr>
    							<tr>
    		
    								<td class="cont_body_tall_l_2"><img src="../content/images/spacer.gif" border="0" alt="" width="1" height="1" /></td>
    								<td width="100%" class="cont_body_td_2"><span class="productSpecialPrice"><?php echo number_format($results[$i]->Price_f);?><br />VNÐ</span></td>
    								<td class="cont_body_tall_r_2"><img src="../content/images/spacer.gif" border="0" alt="" width="1" height="1" /></td>
    							</tr>
    							<tr>
    								<td><img src="../content/images/cont_body_corn_bl_2.gif" border="0" alt="" width="10" height="10" /></td>
    								<td width="100%" class="cont_body_tall_b_2"><img src="../content/images/spacer.gif" border="0" alt="" width="1" height="1" /></td>
    								<td><img src="../content/images/cont_body_corn_br_2.gif" border="0" alt="" width="10" height="10" /></td>
    							</tr>
    						</table>
    						<div style="float:left; width:55px; margin:0 0 0 15px;">
    							<a href="../views/detail.php?id=<?php echo $results[$i]->Code_s; ?>">
    								<div class="detail">
    									Chi tiết
    								</div>
    							</a>
    							<div class="clearall"></div>
                                                        <a href="../views/Cart.php?id=<?php echo $results[$i]->Code_s; ?> ">
    							<div class="addToCart" style="margin:5px 0 0 0; cursor:pointer;">
    								Mua
    							</div>
                                                            </a>
    						</div>
    					</div>
    				</td>  
                        <?php
                            if(++$count % 3 == 0)
                                break;
                            }
                    ?>
    			</tr>
                <?php
                        }
                ?>	
    		</table>
        </div>
        <script type="text/javascript">
            $("ul.pager > li > a").click(function () {
				GetSearchResults($(this).attr("page"), "<?php echo $categoryID; ?>", "<?php echo $colors; ?>", "<?php echo $productName_Get; ?>");
            });
        </script>
		<!-- END DEFINE YOUR CONTENT HERE -->
	</div>
	<div class="box_content_b"></div>
</div>